package com.ruoyi.crm.modules.mq;

import com.ruoyi.crm.domain.Contract;
import com.ruoyi.crm.service.impl.CrmMailService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;

@Component
public class CrmMqConsumer {
    @Resource
    private CrmMailService crmMailService;

    /**
     * 处理合同创建消息，发送邮件和短信通知给用户
     * @param contract
     */
    @RabbitListener(queues = {CrmRabbitConfig.CRM_QUEUE_CONTRACT_CREATED})// 监听指定的队列
    public void consumeContractCreated(Contract contract){
        // 发送邮件
        if (StringUtils.hasText(contract.getEmail())){
            crmMailService.sendContractCreatedMail(contract);
        }
        //发送短信

    }
}
